package com.apes.fn.scm.commodityInquiry.repository;

import com.apes.fn.scm.commodityInquiry.model.ExternalInquiryItem;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface ExternalInquiryItemRepository extends CustomRepository<ExternalInquiryItem, String> {

    @Query(value = "SELECT A.* FROM PUR_EXTERNAL_INQUIRY_ITEM A, PUR_EXTERNAL_INQUIRY B " +
            " WHERE A.EXTERNAL_INQUIRY_ID = B.ID AND EXTERNAL_INQUIRY_ID = ?1 AND VALID_PERIOD >= SYSDATE AND EXTERNAL_INQUIRY_ID || A.ID = ?2 AND B.STATE = 'approve' ", nativeQuery = true)
    Map sourceQueryPriceValid(String externalInquiryId, String unique);

    @Query(value = "" +
            "SELECT A.*\n" +
            "  FROM PUR_EXTERNAL_INQUIRY_ITEM A, PUR_EXTERNAL_INQUIRY B\n" +
            " WHERE A.EXTERNAL_INQUIRY_ID = B.ID\n" +
            "   AND EXTERNAL_INQUIRY_ID = ?1 AND EXTERNAL_INQUIRY_ID || A.ID = ?2 AND B.STATE = 'approve' ", nativeQuery = true)
    ExternalInquiryItem accordIdAndUniqueFind(String externalInquiryId, String unique);
}